package com.yugao.fintech.libra.system;

import com.yugao.fintech.libra.system.model.entity.SysUser;
import com.yugao.fintech.libra.system.model.rqrs.accesskey.AccessKeyResp;
import com.yugao.fintech.libra.system.model.rqrs.log.LoginUserGetReq;
import com.yugao.fintech.libra.system.model.rqrs.log.OperateLogSaveReq;
import com.yugao.fintech.libra.system.model.rqrs.tenant.TenantSaveReq;
import com.yugao.fintech.libra.system.model.rqrs.tenant.TenantUpdateReq;
import com.yugao.fintech.libra.system.model.rqrs.user.LoginUserDeleteReq;
import com.yugao.fintech.libra.system.model.rqrs.user.UserBasePageReq;
import com.yugao.fintech.libra.system.model.rqrs.user.UserResp;
import com.yugao.fintech.libra.system.model.rqrs.user.UserSaveReq;
import com.yugao.fintech.meheco.core.domain.ResultVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Lazy
@FeignClient(contextId = "remoteSystemService", url = "${server-url:}", value = ServiceCodeCons.SYSTEM_SERVICE)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
public interface RemoteSystemService {
    @GetMapping(value = "/accessKey/getAccessKeyBySecretId", headers = SecurityCons.HEADER_FROM_IN)
    Resp<AccessKeyResp> getAccessKeyBySecretId(@RequestParam(value = "secretId") String secretId);

    @GetMapping(value = "/accessKey/getAccessKeyById", headers = SecurityCons.HEADER_FROM_IN)
    Resp<AccessKeyResp> getAccessKeyById(@RequestParam(value = "id") Long id);

    /**
     * 保存日志
     * @param req 日志实体
     * @return succes、false
     */
    @PostMapping(value = "/operateLog/save", headers = SecurityCons.HEADER_FROM_IN)
    Resp<Boolean> saveOperateLog(@RequestBody OperateLogSaveReq req);


    /**
     * 通过账号查询用户信息
     *
     * @return 结果
     */
    @PostMapping(value = "/user/getLoginUser", headers = SecurityCons.HEADER_FROM_IN)
    Resp<LoginUser> getLoginUser(@RequestBody LoginUserGetReq req);

    @PostMapping(value = "/user/save", headers = SecurityCons.HEADER_FROM_IN)
    Resp<Long> saveUser(UserSaveReq req);

    @DeleteMapping(value = "/user/delete", headers = SecurityCons.HEADER_FROM_IN)
    Resp<?> removeUserById(@RequestParam(value = "id") Long userId);

    @GetMapping(value = "/user/delete", headers = SecurityCons.HEADER_FROM_IN)
    Resp<List<UserResp>> listUser(UserBasePageReq query);

    @GetMapping(value = "/user/getById", headers = SecurityCons.HEADER_FROM_IN)
    Resp<UserResp> getUserById(@RequestParam(value = "id") Long userId);

    @PostMapping(value = "/user/deleteLoginUser", headers = SecurityCons.HEADER_FROM_IN)
    Resp<?> deleteLoginUser(LoginUserDeleteReq req);

    @GetMapping(value = "/user/listUserByIds", headers = SecurityCons.HEADER_FROM_IN)
    Resp<List<UserResp>> listUserByIds(@RequestParam(value = "userIds") List<Long> userIds);

    @GetMapping("/user/getUserByAccount")
    Resp<SysUser> getUserByAccount(@RequestParam("account") String account);

    @PostMapping(value = "/tenant/save", headers = SecurityCons.HEADER_FROM_IN)
    Resp<Long> saveTenant(TenantSaveReq req);

    @DeleteMapping(value = "/tenant/delete", headers = SecurityCons.HEADER_FROM_IN)
    Resp<?> deleteTenant(@RequestParam("id") Long tenantId);

    @PostMapping(value = "/tenant/update", headers = SecurityCons.HEADER_FROM_IN)
    Resp<?> updateTenant(TenantUpdateReq req);

    @Operation(description = "获取使用的配置")
    @GetMapping("/config/getUseConfig")
    Resp<ConfigInfo> getUseConfig(@RequestParam("configDefine") String configDefine);
    
    /**
     * 获取角色权限(忽略租户)
     * @param roleIds 角色id
     * @return key: 模块名, key: 可访问的资源路径集合
     */
    @GetMapping("/role/listAssignUrl")
    Resp<Map<String, List<String>>> listAssignRoleUrl(@RequestParam("roleIds") List<Long> roleIds);
}
